package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.NanGame;
import com.tsingtree.modular.mapper.NanGameMapper;
import com.tsingtree.modular.model.params.NanGameParam;
import com.tsingtree.modular.model.result.NanGameResult;
import  com.tsingtree.modular.service.NanGameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;


/**
 * <p>
 * 游戏 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-05-08
 */
@Service
public class NanGameServiceImpl extends ServiceImpl<NanGameMapper, NanGame> implements NanGameService {

    @Override
    public void add(NanGameParam param){
        NanGame entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanGameParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(NanGameParam param){
        NanGame oldEntity = getOldEntity(param);
        NanGame newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public NanGameResult findBySpec(NanGameParam param){
        return null;
    }

    @Override
    public List<NanGameResult> findListBySpec(NanGameParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(NanGameParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(NanGameParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private NanGame getOldEntity(NanGameParam param) {
        return this.getById(getKey(param));
    }

    private NanGame getEntity(NanGameParam param) {
        NanGame entity = new NanGame();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
